package com.web;

import com.domain.actPlan;
import com.service.userService;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
/**
 * 客户完善活动的数据，完善反馈和评分
 * 接收 updateAPASelf.jsp 页面的表单数据，封装成actPlan对象
 * 提交到 userService 的 updateUserActivity 函数
 * 重定向到 /ShowUserAct
 */
@WebServlet("/updateUserActivity")
public class updateUserActivityServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.解决乱码问题
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        //2.接收页面表单数据
        Map<String, String[]> map = request.getParameterMap();
        //3.进行封装
        actPlan acp = new actPlan();
        try {
            BeanUtils.populate(acp, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //5.修改
        System.out.println("正在修改" + acp +"的用户");
        new userService().updateUserActivity(acp);
        //4.重定向到显示客户参与的活动,并把用户id一起带过去
        response.sendRedirect(request.getContextPath()+"/ShowUserAct?userId="+acp.getUserId());
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
